#!/bin/bash

echo "正在启动简易文件分享工具..."
echo ""

# 检查是否安装了Python
if command -v python3 &> /dev/null; then
    PYTHON_CMD="python3"
elif command -v python &> /dev/null; then
    # 检查Python版本
    PYTHON_VER=$(python -c "import sys; print(sys.version_info.major)")
    if [ "$PYTHON_VER" -eq "3" ]; then
        PYTHON_CMD="python"
    else
        echo "错误: 您的系统上有Python，但不是Python 3"
        echo "请安装Python 3后再试"
        echo "您可以从 https://www.python.org/downloads/ 下载"
        echo ""
        exit 1
    fi
else
    echo "错误: 未检测到Python安装，请先安装Python 3"
    echo "您可以从 https://www.python.org/downloads/ 下载"
    echo ""
    exit 1
fi

# 添加执行权限
chmod +x file_share_server.py
chmod +x simple_file_share.py

# 尝试启动文件服务器
$PYTHON_CMD file_share_server.py

# 如果功能齐全的服务器启动失败，尝试启动简化版
if [ $? -ne 0 ]; then
    echo ""
    echo "尝试启动简化版服务器..."
    $PYTHON_CMD simple_file_share.py
fi

echo "按 Ctrl+C 停止服务器" 